package com.tykboot.entity;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tykboot.core.base.BaseEntity;
import com.tykboot.model.CurrencyAmount;
import org.hibernate.annotations.GenericGenerator;

import java.util.Date;
import javax.persistence.*;

/**
 * 
 *
 * @author LiuYu
 */ 
@Entity
@Table(name = "tb_direct_debit")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class TbDirectDebit extends BaseEntity {

	/**
	 * 
	 */ 
	@Id
	@GeneratedValue(generator = "jpa-uuid")
	@Column(name = "directDebitId")
	private String directDebitId;

	/**
	 * 
	 */
	@JsonIgnore
	@Column(name = "financialId")
	private String financialId;

	/**
	 * 
	 */ 
	@Column(name = "accountId")
	private String accountId;

	/**
	 * 
	 */ 
	@Column(name = "mandateIdentification")
	private String mandateIdentification;

	/**
	 * 
	 */ 
	@Column(name = "directDebitStatusCode")
	private String directDebitStatusCode;

	/**
	 * 
	 */ 
	@Column(name = "name")
	private String name;

	/**
	 * 
	 */ 
	@Column(name = "previousPaymentDateTime")
	private Date previousPaymentDateTime;

	/**
	 * 
	 */
	@JsonIgnore
	@Column(name = "previousPaymentAmount")
	private String previousPaymentAmountDb;

	@Transient
    private CurrencyAmount previousPaymentAmount;

	public String getDirectDebitId(){
		return directDebitId;
	}

	public void setDirectDebitId(String directDebitId){
		this.directDebitId=directDebitId;
	}

	public String getFinancialId(){
		return financialId;
	}

	public void setFinancialId(String financialId){
		this.financialId=financialId;
	}

	public String getAccountId(){
		return accountId;
	}

	public void setAccountId(String accountId){
		this.accountId=accountId;
	}

	public String getMandateIdentification(){
		return mandateIdentification;
	}

	public void setMandateIdentification(String mandateIdentification){
		this.mandateIdentification=mandateIdentification;
	}

	public String getDirectDebitStatusCode(){
		return directDebitStatusCode;
	}

	public void setDirectDebitStatusCode(String directDebitStatusCode){
		this.directDebitStatusCode=directDebitStatusCode;
	}

	public String getName(){
		return name;
	}

	public void setName(String name){
		this.name=name;
	}

	public Date getPreviousPaymentDateTime(){
		return previousPaymentDateTime;
	}

	public void setPreviousPaymentDateTime(Date previousPaymentDateTime){
		this.previousPaymentDateTime=previousPaymentDateTime;
	}

    public String getPreviousPaymentAmountDb() {
        return previousPaymentAmountDb;
    }

    public void setPreviousPaymentAmountDb(String previousPaymentAmountDb) {
        this.previousPaymentAmountDb = previousPaymentAmountDb;
    }

    public CurrencyAmount getPreviousPaymentAmount() {
		if (previousPaymentAmount != null) {
			return previousPaymentAmount;
		}
		return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getPreviousPaymentAmountDb())), CurrencyAmount.class);
	}

    public void setPreviousPaymentAmount(CurrencyAmount previousPaymentAmount) {
		this.previousPaymentAmount = previousPaymentAmount;
    }
}

